package com.xuxk.project.library.controller.api;

import com.github.pagehelper.Page;
import com.xuxk.project.library.annotation.LibraryLog;
import com.xuxk.project.library.bean.XuxkMenu;
import com.xuxk.project.library.service.XuxkMenuService;
import com.xuxk.project.library.util.PageInfoVo;
import com.xuxk.project.library.util.PageUtil;
import com.xuxk.project.library.util.RequestUtils;
import com.xuxk.project.library.util.ResultBodyVo;
import com.xuxk.project.library.vo.XuxkMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 *   @author  橙云科技有限公司
 */

@RequestMapping("/api/xuxkMenu")
@RestController
public class XuxkMenuController {

    @Autowired
	XuxkMenuService xuxkMenuService;


    /**
     * 分页查询
     * @param pageNum  页码
     * @param pageSize 页行数
     * @param request
     *
     * @return
     */
    @GetMapping(value = "/v1.0/xuxkMenus", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "分页查询菜单信息列表")
	public ResultBodyVo xuxkMenus(Integer pageNum, Integer pageSize, HttpServletRequest request){

        Map<String,Object> paramMap = RequestUtils.getQueryParams(request);
        Page<XuxkMenuVo> pageResult = xuxkMenuService.listXuxkMenus(paramMap, PageUtil.getPageParam(pageNum,pageSize));

		return new ResultBodyVo(new PageInfoVo(pageResult)) ;
	}




    @GetMapping(value="/v1.0/xuxkMenus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "查询菜单信息")
    public ResultBodyVo getXuxkMenu(@PathVariable Integer id) {
        XuxkMenu xuxkMenu = xuxkMenuService.getXuxkMenu(id);

        return new ResultBodyVo(xuxkMenu);
    }


    @PostMapping(value="/v1.0/xuxkMenus", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "新增菜单信息")
    public ResultBodyVo saveXuxkMenu(@RequestBody XuxkMenu xuxkMenu) {
        return  new ResultBodyVo(xuxkMenuService.insertXuxkMenu(xuxkMenu));

    }


    @PatchMapping(value="/v1.0/xuxkMenus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "修改部分菜单信息")
    public ResultBodyVo patchUpdateXuxkMenu(@PathVariable Integer id,@RequestBody XuxkMenu xuxkMenu) {
        xuxkMenu.setId(id);
        return  new ResultBodyVo(xuxkMenuService.patchUpdateXuxkMenu(xuxkMenu));


    }

    @PutMapping(value="/v1.0/xuxkMenus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultBodyVo updateXuxkMenu(@PathVariable Integer id,@RequestBody XuxkMenu xuxkMenu) {

        xuxkMenu.setId(id);
        return new ResultBodyVo(xuxkMenuService.updateXuxkMenu(xuxkMenu));
    }


    @DeleteMapping(value="/v1.0/xuxkMenus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "删除菜单信息")
    public ResultBodyVo deleteXuxkMenu(@PathVariable Integer id) {

        xuxkMenuService.deleteXuxkMenu(id );

        return new ResultBodyVo(1) ;

    }

}
